function createPager(page, pageNumber, mostNumber, container) {
    container.innerHTML = '';

    let pagerContainer = document.createElement('div');
    pagerContainer.className = 'pager';

    function createAnthor(className, text, newPage) {
        let a = document.createElement('a');
        a.className = className;
        a.innerText = text;
        pagerContainer.appendChild(a);
        a.onclick = function () {
            if (newPage < 0 || newPage > pageNumber || newPage === page) {
                return
            }
            createPager(newPage, pageNumber, mostNumber, container)
        }

    }

    if (page === 1) {
        createAnthor('disabled', '首页', 1);
        createAnthor('disabled', '上一页', page - 1);
    } else {
        createAnthor('', '首页', 1);
        createAnthor('', '上一页', page - 1);
    }

    let min = Math.floor(page - mostNumber / 2)
    if (min < 1) {
        min = 1;
    }
    let max = min + mostNumber - 1;
    if (max > pageNumber) {
        max = pageNumber;
    }
    if (max - min !== mostNumber) {
        min = max - mostNumber;
    }
    for (let i = min; i <= max; i++) {
        if (i === page) {
            createAnthor('active', i, i);
        } else {
            createAnthor('', i, i);
        }
    }

    if (page === pageNumber) {
        createAnthor('disabled', '下一页', page + 1);
        createAnthor('disabled', '尾页', pageNumber);
    } else {
        createAnthor('', '下一页', page + 1);
        createAnthor('', '尾页', pageNumber);
    }

    let span = document.createElement('span');
    span.innerText = page + '/' + pageNumber;
    pagerContainer.appendChild(span);

    container.appendChild(pagerContainer);
}

let container = document.querySelector('.pagerContainer');
createPager(1, 50, 10, container);